Now let's make our knockback for Chuck Norris kick.
So I'm going to go to the move on PC, which should probably change because it's no longer just doing
movement, but it's fine for now.
Let's go.
This is the top of the script where the variables are right underneath that.
I'm going to make a function, local function.
I'm going to call it knockback, and I'm going to keep this very general.
So I'm not going to use any global variables because I want to move this to other things like my pistol,
stuff like that or somebody else's punch.
So I'm going to need two characters.
I'm going to do one for the attack character and the other for the enemy character.
Right?
And I'll just do a quick check to see if the charge are there.
So if a char and each are, then now I'm going to need the humanoid root parts of both of those and
I know we have I humanoid root part, but like I said, I want to keep the self contained.
So let's get it again.
Let's call this a four attack humanoid root part.
We're going to get it from the air.
We'll do a find first child because if it's not there, we don't want to wait for it because it might
take 2 seconds to come back in the world and we'll do a humanoid root part and then we'll do one for
the enemy.
HRP.
Equals e char.
Find first child.
Whoops.
I got a capital U in there.
Don't put a capital U in their humanoid root part.
I'm starting to lose it.
All right, now let's do a check for those just to make sure that they were found.
So I'll say if a HPE and e HPE, then now we need to find the direction between those two characters
or those two humanoid root parts because we want to send them send the person who's getting knocked
back back, right?
We don't want them to just go behind us or go in any random direction.
So let's get a direction vector, say local deer.
I want to get my hr p position, subtract it from my a hpe's position.
Right?
So that's a direction vector, but we don't know the length.
Let's make it a unit vector so we can calculate force and we're just getting the direction and so the
vectors of magnitude one.
All right.
Now the new body movers like vector force and angular force need an attachment that's slightly different
than the old ones if you're used to the body, the body movers.
So let's make an attachment.
Let's say eight for attachment instance.
No attachment.
There it is.
And we will parent it to the enemy.
Humanoid root part.
And now I'm going to need a vector force.
I'll just call the F.
That's going to be an instance new vector force, and I will make that on the humanoid root part.
Now we need to get the vector forces attachment zero and a sign attached to it.
And now we'll get the vector forces force.
We're going to use our dir.
The direction vector was a deer, but I wanted to go up a little bit.
Right.
So I want to knock them in the air, not just straight back.
So let's add a vector three dot new.
We'll do zero and one and zero.
I'll go ahead and normalize that to the unit vector to also, I should say, and then I'm going to multiply
this by 10,000.
That might be that might be too much, but we can play around with these numbers.
So if you want to take the force going back up upwards and away, you're going to reduce this number
right here.
Now let's do v f, and we have to choose whether we want to do relative to the world or relative to
the attachment.
Right?
So we have our vector force relative to e m, and this is crazy actuator relative to, Oh, I haven't
done anything with actuators in this course, so activate a relative to its OC.
They just use the e name for this for a lot of different things that have attachments where you're going
to have an issue of whether you want to relative to the attachment or relative to the world.
We're going to pick the world.
And then what else do we need?
0vf We need to know whether we want to apply the force at the center of mass.
And we do or where it's attached, right?
Those are your two options.
So we'll say true.
Apply to center of mass.
Now we need our rotational force.
Let's go up a little bit.
So I'll call that root for rotation.
And what have we got?
Instance Dot knew we need angular velocity for this, and then that's going to be on the enemy humanoid
root part.
We'll get our rot.
Let's use attachment, the attachment we created above that attached.
So we'll put the rotational force on that same attachment.
Let's see now let's do rot angular velocity.
All right.
And this is going to be a vector three new.
I'll make a one by one by one.
And this is going to be how many times something spins around per unit of time.
30 gives it a pretty good spin.
So this is a this is a vector.
But if we multiply it by a scalar, it's going to be 30, 30 and 30.
I just think it's easier to change if you're playing around with numbers.
If you have the scalar on the end, what else are we going to need?
We're going to need wrought max torque and we'll just make that math huge, right?
So that's the maximum torque we can apply.
We want to apply as much as we need.
All right.
We'll do the game debris service to clean up all these parts that we put on somebody's humanoid root
part.
We'll do a add item.
So we have our vector force you have to get rid of.
We'll let it live for 0.2 seconds because the vector force will continue to push on the character and
it'll fly away forever if we don't destroy it.
So we'll do game debris, service, colon.
We need an add item for the attachment.
We'll make that point two I will do game debris, add item for the rot, the rotational force make that
point too.
So for a quick recap, we have two forces acting on our enemies humanoid root part using this attachment
which is attached to the humanoid root part, the enemy's humanoid root part.
So we have a vector force which is going to push them back.
And we also have this angular velocity, right?
That's rot and that's going to spin them, right?
And we're always going to spin in the same direction.
These are axes of rotation right here.
And let's go ahead and try it out, see what we got.
We've got to call this first.
Remember, we have our attacking char and our enemy char go down to where we do our kick.
So whenever you go to apply that knockback, you're going to look for where you take damage.
Let's see, we do this.
Let's do the damage.
Let's do the knockback right after we do the damage.
So I'll say knockback.
I want my attacking help.
Well, that's easy enough.
That's our I, not HP NPC.
We need our AI NPC and we need the enemies chart.
We don't have the enemies cha.
We do have the closest humanoid root part though.
That's all right.
Because if we have the closest humanoid root part or the closest humanoid, the parent is the cha,
we are good to go.
Let's see what we got.
Hit the play button.
MPC work.
Here we go.
There's Chuck.
Maybe.
Should we put our.
Let's get our output window.
We'll check it out for you.
Kicks us.
Boom.
Pretty cool.
Do it again.
We'll do with that.
We'll do it with the output window.
Nice.
I'm liking it.
All right.
That's pretty cool.
And we can create the distance of it or we can increase the distance of interest if we want them to
chase after us to.